<template>
  <div>
    <el-form ref="form" :model="link" label-width="80px">
      <el-form-item label="链接名称">
        <el-input ref="linkName" v-model="link.linkName" />
      </el-form-item>
      <el-form-item label="链接地址">
        <el-input ref="linkUrl" v-model="link.linkUrl" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">确认</el-button>
        <el-button @click="closeForm">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import linkApi from '@/api/link'
export default {
  props: {
    link: {
      type: Object,
      default: null
    }
  },
  created() {
    this.$nextTick(() => {
      this.$refs.linkName.focus()
    })
  },
  methods: {
    onSubmit() {
      linkApi.update(this.link).then(resp => {
        this.$message.success(resp.msg)
        this.$emit('list')
        this.$emit('closeUpdateForm')
      })
    },
    closeForm() {
      this.$emit('closeUpdateForm')
    }
  }
}
</script>
